import type { RouteRecordRaw } from 'vue-router'
import { coreRoutes } from './core'
import { loadRouteModules } from '@/utils/router'

// 项目静态路由
const dynamicRoutesFiles = import.meta.glob('./modules/**/*.ts', {
    eager: true,
})

const externalRoutesFiles = import.meta.glob('./external/**/*.ts', {
    eager: true,
})

// 动态路由,依赖layout
const dynamicRoutes: RouteRecordRaw[] = loadRouteModules(dynamicRoutesFiles)
// 外部路由，访问这些页面不需要layout
const externalRoutes: RouteRecordRaw[] = loadRouteModules(externalRoutesFiles)

/** 外部路由，不依赖BaseLayout */
// 初始仅注册核心路由，404 等待动态路由生成后再追加
const routes: RouteRecordRaw[] = [...coreRoutes, ...externalRoutes]

// 获取无需校验的路由name（不包含 404）
const coreRouteNames = [...coreRoutes].map((route) => route.name)

// 有权限校验的路由列表，包含动态路由和静态路由
const accessRoutes: RouteRecordRaw[] = [...dynamicRoutes]


export { coreRouteNames, accessRoutes, routes }
